package com.lkc.service.impl;

import com.lkc.annotation.LogMethod;
import com.lkc.bean.Products;
import com.lkc.mapper.ProductsDao;
import com.lkc.service.ProductsService;
import com.lkc.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductsServiceImpl implements ProductsService {

    @Autowired
    private ProductsDao productsDao;

    @Override
    @LogMethod(serviceName = "商品服务", recordParam = true, recordReturn = true)
    public Products add(Products products) {
        productsDao.add(products);
        return productsDao.one(products.getProductId());
    }

    @Override
    @LogMethod(serviceName = "商品服务", recordParam = true, recordReturn = true)
    public int del(Integer productId) {
        return productsDao.del(productId);
    }

    @Override
    @LogMethod(serviceName = "商品服务", recordParam = true, recordReturn = true)
    public Products edit(Products products) {
        productsDao.edit(products);
        return productsDao.one(products.getProductId());
    }

    @Override
    @LogMethod(serviceName = "商品服务", recordParam = true, recordReturn = false)
    public List<Products> all(Products products) {
        return productsDao.all(products);
    }

    @Override
    @LogMethod(serviceName = "商品服务", recordParam = true, recordReturn = true)
    public Products one(Integer productId) {
        return productsDao.one(productId);
    }

    @Override
    @LogMethod(serviceName = "商品服务", recordParam = true, recordReturn = false)
    public void page(Page page, Products products) {
        int count = productsDao.pageCount(products);
        Object data = productsDao.page(page, products);
        page.setCount(count);
        page.setData(data);
    }
}
